package ch08;

import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.time.*;

public class DateMain {
    public static void main(String[] args) {
        Date today = new Date();
        System.out.println(today);
        System.out.println(today.getTime());
        System.out.println(System.currentTimeMillis());

        String str = "2023-06-20";
        System.out.println(java.sql.Date.valueOf(str)); // 子类Date   sql  ->  util

        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);
        System.out.println(calendar.getTime());

        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);

        LocalTime localTime = LocalTime.now();
        System.out.println(localTime);

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        String str1 = localDate.format(formatter);
        System.out.println(str1);
        String str2 = formatter.format(localDate);
        System.out.println(str2);

        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        String str3 = localDateTime.format(formatter2);
        System.out.println(str3);

        LocalDate localDate2 = LocalDate.parse(str);
        String str4 = localDate2.format(formatter);
        System.out.println(str4);

        localDate = localDate.plusYears(-2).plusMonths(3);
        System.out.println(localDate.getYear());
        System.out.println(localDate.getMonth());
        System.out.println(localDate.getDayOfMonth());
        System.out.println(localDate.getDayOfWeek());
    }
}
